package com.xiye.im.netty.server.handler;

import com.xiye.im.netty.process.MsgProcessor;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * @Package com.xiye.im.netty.server.handler
 * @Description 心跳检测
 * @Author 西野
 * @Date 2018-09-13
 * @Version V1.0
 */
public class ImIdleHandler extends IdleStateHandler implements ChannelHandler {

    public ImIdleHandler(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) {
        super(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds);
    }

    public ImIdleHandler(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) {
        super(readerIdleTime, writerIdleTime, allIdleTime, unit);
    }

    @Override
    public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception {
        MsgProcessor process = new MsgProcessor();
        process.logout(ctx.channel());
        ctx.channel().close();
    }
}
